<%@ include file="common.jsp"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style type="text/css">
body {
	overflow-x: hidden;
	overflow-y: hidden;
	padding: 15px 15px 0 0;
}
</style>
<link rel="stylesheet" type="text/css" href="../../js/bootstrap-datetimepicker.min.css">
</head>
<body>
	<form class="form-horizontal">
		<div class="form-group">
			<label class="col-sm-2 control-label">卡号：</label>
			<div class="col-sm-10">
				<input type="text" class="form-control" name="rid">
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-2 control-label">状态：</label>
			<div class="col-sm-4">
				<select class="form-control" name="state">
					<option value="1">未充值</option>
					<option value="-1">已充值</option>
				</select>
			</div>
			<label class="col-sm-2 control-label">充值用户：</label>
			<div class="col-sm-4">
				<input type="text" class="form-control" name="rechargeUser">
			</div>
		</div>
		<div class="form-group">
			<label class="col-sm-2 control-label">充值时间：</label>
			<div class="col-sm-4">
				<div class="input-group">
					<input class="form-control date form_datetime" type="text"
						id="rechargeTime" name="rechargeTime" readonly> <span
						class="input-group-addon" onclick="cleanTimePicker('rechargeTime')"
						style="cursor: pointer;"> <span class="add-on"><i
							class="fa fa-times"></i></span>
					</span>
				</div>
			</div>
			<label class="col-sm-2 control-label">推荐人：</label>
			<div class="col-sm-4">
				<input type="text" class="form-control" name="recommend">
			</div>
		</div>
		
		<div class="form-group">
			<div class="col-sm-1 col-sm-offset-2">
				<button class="btn btn-default" type="button" onclick="update()">保存</button>
			</div>
			<div class="col-sm-1">
				<button class="btn btn-default" type="button" onclick="closeLayer()">返回</button>
			</div>
		</div>
	</form>
</body>
<script type="text/javascript" src="../../js/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript">
	var card;
	var $rid = $('input[name="rid"]');
	var $state = $('select[name="state"]');
	var $rechargeUser = $('input[name="rechargeUser"]');
	var $rechargeTime = $('input[name="rechargeTime"]');
	var $recommend = $('input[name="recommend"]');

	$(function() {
		// 初始化时间控件
		$(".form_datetime").datetimepicker({
			format : "yyyy-mm-dd", // 选择日期后，文本框显示的日期格式
			autoclose : true, // 选择日期后自动关闭
			startView : 2,
			minView : 2,
			todayBtn : true
		});

		card = parent.map[parent.id];
		$rid.val(card.rid);
		$state.val(card.state);
		$rechargeUser.val(card.rechargeUser);
		$rechargeTime.val(card.rechargeTime);
		$recommend.val(card.recommend);
	});

	function update() {
		if (validate()) {
			var url = BaseUrl + 'rechargeCardAction/updateCardById.action';
			var option = {};
			option['id'] = card.id;
			option['rid'] = $rid.val();
			option['state'] = $state.val();
			option['rechargeUser'] = $rechargeUser.val();
			option['rechargeTime'] = $rechargeTime.val();
			option['recommend'] = $recommend.val();
			$.a(url, option, function(res) {
				if (res.result) {
					parent.load();
					parent.layer.msg('保存成功', {
						time : 2000
					});
					closeLayer();
				} else {
					parent.layer.msg(res.message, {
						time : 2000
					});
				}
			}, false);
		}
	}

	function validate() {
		if (isEmpty($rid.val())) {
			layer.msg('卡号不能为空', {time : 2000});
			$rid.focus();
			return false;
		}
		return true;
	}

	function closeLayer() {
		var index = parent.layer.getFrameIndex(window.name);
		parent.layer.close(index);
	}

	// 清除日期控件
	function cleanTimePicker(id) {
		if (id) $("#" + id).val("");
	}
</script>
</html>